﻿HmJS.$Import('core.core');

/*
---
name: String.Common
version: 0.3-1
description: Common String hash-related methods.
license: MIT-style
download: http://mootools.net/forge/p/string_cryptography
source: http://github.com/sixtyseconds/mootools-string-cryptography
authors: [Christopher Pitt, Enrique Erne]
requires: 
- Core/String
provides: [String.toBin]
...
*/

HmJS.register('crypt.string.cryptographycommon', function ($ns) {

	String.implement({
		'toBin': function (size, littleEndian) {
			var bin = Array(),
					mask = (1 << size) - 1;

			for (var a = 0, len = this.length * size; a < len; a += size) {
				var modifier = littleEndian ?
					(a % 32) :
					(24 - a % 32);

				bin[a >> 5] |= (this.charCodeAt(a / size) & mask) << modifier;
			}

			return bin;
		}
	});

});
